<template>
  <div>
    <teleport to="body">
      <transition name="fade" v-if="isShowPopup" @click="isShowPopup = false">
        <div class="w-screen h-screen bg-zinc-900/80 fixed top-0 left-0 z-40 " />
      </transition>
      <transition name="popup-down-up" v-if="isShowPopup">
        <div v-bind="$attrs" class="w-screen dark:bg-zinc-800 bg-white z-50 fixed bottom-0 rounded-t-[5px]">
          <slot />
        </div>
      </transition>
    </teleport>
  </div>
</template>

<script setup>
import { watch } from 'vue'
import { useScrollLock, useVModel } from '@vueuse/core'

const props = defineProps({
  modelValue: {
    type: Boolean,
    required: true
  }
})

const isShowPopup = useVModel(props)

const isLocked = useScrollLock(document.body)
watch(
  () => isShowPopup,
  (val) => {
    // console.log('isLocked',isLocked);
    isLocked.value = val
  },
  { immediate: true }
)

// const emit = defineEmits(['update:modelValue'])
</script>
<style scoped>
.fade-enter-active,
.fade-leave-active,
.popup-down-up-enter-active,
.popup-down-up-leave-active {
  transition: opacity 0.3s;
}
.fade-enter-from,
.fade-leave-to {
  opacity: 0;
}
.popup-down-up-enter-from,
.popup-down-up-leave-to {
  transform: translateY(100%);
}
</style>
